/*
* @Date: 2021/2/2
* @Author: XueChengwu <xuechengwu@erayt.com>
* @Copyright: 2015-2019 Erayt, Inc.
* @Description: If you have some questions, please contact: xuechengwu@erayt.com.
*/
import React from 'react';
import { Tree } from 'antd';
import './index.scss';
const TreeNode = Tree.TreeNode;

export default class extends React.Component {
  constructor(props) {
    super(props);
  }

  onDrop = (e, node, dragNode, keys) => {

  }

  onSelect = (keys, e) => {

  }

  render() {
    const loop = data => {
      if (data === null) {
        return null;
      }
      if (!(data instanceof Array)) {
        if (data.children) {
          return <TreeNode key={data.key} title={data.label}>{loop(data.children)}</TreeNode>;
        }
        return <TreeNode key={data.key} title={data.label} />
      }
      return data.map((item) => {
        if (item.children) {
          return <TreeNode key={item.key} title={item.label}>{loop(item.children)}</TreeNode>;
        }
        console.log(item.label, item);
        return <TreeNode key={item.key} title={item.label} />;
      })
    };
    return (
      <div className="component-tree">
        <Tree
          className="draggable-tree"
          draggable
          onDrop={this.onDrop}
          onSelect={this.onSelect}
        >
          {loop(this.props.data)}
        </Tree>
      </div>
    );
  }
}
